<template>
	<view>
		<view class="top">
			<coupon-con :item="item" :isDetail="true"></coupon-con>
		</view>
		
		<view v-if="item.remark" class="discription">
			<view class="label">
				使用说明
			</view>
			<view class="discription-text">
				{{item.remark}}
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState, mapGetters, mapMutations } from 'vuex';
	import couponCon from '../index/couponCon'
	export default {
		data() {
			return {
				couponId: '',
				item: {}
			};
		},
		components: {
		  couponCon: couponCon
		},
		onLoad(data) {
			this.couponId = data.couponId || ''
			this.init()
		},
		onShow() {
			
		},
		computed:{
			...mapState(['userInfo','accessToken']),
		},
		methods:{
			async init() {
				const param = {
					'ACCESS-TOKEN': this.accessToken
				}
				const res = await this.$api.getCouponDetail(param, this.couponId)
				if(res && res.code == 200) {
					this.item = res.data
				}
			},
			toGoodsDetail(){
				let item = this.item
				if(item.useType == '1' && item.limitClassId!='0'){
					uni.navigateTo({
						url: `/course/detail/detail?id=${item.limitClassId}`
					})
				}else if(item.useType == '2' && item.limitActId!='0'){
					uni.navigateTo({
						url: `/activity/detail/detail?id=${item.limitActId}`
					})
				}
			},
			useCoupon(item) {
			  let url = ''
			  // 平台下
			  if (item.grantType == '1') {
			    // 平台下现金、满减、折扣
			    if (item.type != '4') {
			      // 课程、活动通用
			      if (item.useType == '0') {
			        // 通用跳转首页
			        uni.reLaunch({
			           url: '/pages/index/index'
			        })
			        return
			      } else if (item.useType == '1') {
			        // 仅课程
			        if (item.limitClassId!='0') {
			          // 指定课程
			          url = `/course/detail/detail?id=${item.limitClassId}`
			        }else {
			          // 全部课程
			          uni.reLaunch({
			             url: '/pages/course/index/index'
			          })
			          return
			        }
			      } else {
			        // 仅活动
			        if (item.limitActId!='0') {
			          // 指定活动
			          url = `/activity/detail/detail?id=${item.limitActId}`
			        } else {
			          // 全部活动
			          uni.reLaunch({
			             url: '/pages/activity/index/index'
			          })
			        }
			      }
			    } else {
			      // 平台下兑换券
			      url = `/mainProcess/confirmOrder/confirmOrder?couponId=${item.id}&type=class&id=${item.limitClassId}`
			    }
			  } else {
			    // 俱乐部下现金、满减、折扣
			    if (item.type != '4') {
			      // 课程、活动通用
			      if (item.useType == '0') {
			        // 通用跳转俱乐部详情
			        url= `/mainProcess/club/detail/detail?id=${item.clubId}`
			      } else if (item.useType == '1') {
			        // 仅课程
			        if (item.limitClassId!='0') {
			          // 指定课程
			          url = `/course/detail/detail?id=${item.limitClassId}`
			        }else {
			          // 全部课程
			          url= `/mainProcess/club/detail/detail?id=${item.clubId}`
			
			        }
			      } else {
			        // 仅活动
			        if (item.limitActId!='0') {
			          // 指定活动
			          url = `/activity/detail/detail?id=${item.limitActId}`
			        } else {
			          // 全部活动
			          url= `/mainProcess/club/detail/detail?id=${item.clubId}`
			        }
			      }
			    } else {
			      // 俱乐部兑换券
			      url = `/mainProcess/confirmOrder/confirmOrder?couponId=${item.id}&type=class&id=${item.limitClassId}`
			    }
			  }
			  uni.navigateTo({
			     url: url
			  })
			}
		},
		filters: {
		  timeLimit (time) {
		    let time1 = time.split(' ')[0]
		    return time1.replace(/-/g, '.')
		  }
		}
	}
</script>

<style lang="scss">
	.top{
		background-color: #F2F2F2;
		padding-bottom: 20rpx;
	}
	.discription{
		padding: 30rpx 35rpx;
		.label{
			
		}
		.discription-text{
			word-break: break-all;
			font-size: 26rpx;
			color: #999;
			line-height: 48rpx;
		}
	}
</style>
